<?php


namespace app\api\controller;

use app\admin\model\SaasBOrder as SBO;
use app\admin\model\SaasBusiness;
use think\Request;

class SaasFinance extends Base
{
    public function getBusinessTotalFinance(Request $request){
        $res = [];
        $data = $request->post();
        if(!isset($data['user_id'])){
            $res['status'] = 400;
            echo json_encode($res);die;
        }

        $sb = new SaasBusiness();
        $sbo = new SBO();
        //查询商家的店铺id
        $getBid = $sb->getOne($data);
        $where['b_id'] = $getBid['id'];
        $rs = $sbo->getAll($where);
        $fin = [];
        foreach($rs as $k){
            //订单收益
            if($k['status'] != 1) {
                $fin['ddsy'][] = $k['goods_number'] * $k['goods_price'];
            }
            //可提现
            if($k['status'] == 4){
                $fin['ktx'][] = $k['goods_number'] * $k['goods_price'];
            }
            //不可提现
            if($k['status'] == 2 or $k['status'] == 3){
                $fin['bktx'][] = $k['goods_number'] * $k['goods_price'];
            }
        }

        $fin['ddsy'] = sprintf("%.2f", !isset($fin['ddsy'])?0:array_sum($fin['ddsy']));
        $fin['ktx'] = sprintf("%.2f", !isset($fin['ktx'])?0:array_sum($fin['ktx']));
        $fin['bktx'] = sprintf("%.2f", !isset($fin['bktx'])?0:array_sum($fin['bktx']));
        if($fin){
            $res['data']['code'] = 1;
            $res['data']['msg'] = "查询成功";
            $res['data']['list'] = $fin;
        }else{
            $res['data']['code'] = 0;
            $res['data']['msg'] = "查询失败";
        }
        $res['status'] = 200;
        echo json_encode($res);
    }
}